package com.surfilter.util;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;

public class ProcessUtil {
	
	public static Map<String, Long> sortMap(Map<String, Long> oldMap) {
		if(oldMap == null)
		   return oldMap;
        ArrayList<Map.Entry<String, Long>> list = new ArrayList<Map.Entry<String, Long>>(oldMap.entrySet());  
        Collections.sort(list, new Comparator<Map.Entry<String, Long>>() {
			public int compare(Entry<String, Long> o1, Entry<String, Long> o2) {
				return (int) (o2.getValue() - o1.getValue());
			}
        });  
        Map<String, Long> newMap = new LinkedHashMap<String, Long>();
        for (int i = 0; i < list.size(); i++) {  
            newMap.put(list.get(i).getKey(), list.get(i).getValue());  
        }  
        return newMap;
    }
}
